import fetch from '../assets/js/fetch'
import {getVilidAttrWithEmpty,isEmpty} from '../assets/js/assist'

/**
 *
 方法说明 获取代理列表
 *
 @method SYS_Product_add
 *
 @param  {Object} options 请求参数

 *
 @return {Object} 若code为0表示成功,返回data,执行then方法,否则执行catch方法
 */
export default function SYS_Product_add (options) {
  if(isEmpty(options.CategoryId))
  {
      return Promise.reject('未传递CategoryId参数');
  }
  if(isEmpty(options.Title))
  {
      return Promise.reject('未传递Title参数');
  }
  if(isEmpty(options.SubTitle))
  {
      return Promise.reject('未传递SubTitle参数');
  }
  if(isEmpty(options.AveragePrice))
  {
      return Promise.reject('未传递AveragePrice参数');
  }
  if(isEmpty(options.Price))
  {
      return Promise.reject('未传递Price参数');
  }
  if(isEmpty(options.ActivityPrice))
  {
      return Promise.reject('未传递ActivityPrice参数');
  }
  if(isEmpty(options.DetailText))
  {
      return Promise.reject('未传递Series参数');
  }

    options = getVilidAttrWithEmpty(options);
    return new Promise((resolve, reject) => {
        fetch({
            url:'/protocal/SYS_Product/SYS_Product_add.ashx',
            method: 'post',
            data:options
        }).then((result) => {
            const data = result.data;
            const total = result.total;
            const code = result.code;
            const message = result.msg;
            if (code == "1") {
                resolve(data,total);
            } else {
                reject(message);
            }
        })
        .catch((err) => {
            if (err) {
                console.log(err);
            }
            reject(err);
        });
    });
}
